home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Video
/
World of Video.iso
/
gfxprograms
/
3dprograms
/
t3dlib
/
source
/
freeworld.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-02-13
|
4KB
|
145 lines
/* freeworld.c - free a TTDDDLIB WORLD * object
* - written by John T. Grieggs - 12-3-91
* - Thanks, John! [--Glenn]
*/
static char rcs_id[] = "$Id: freeworld.c,v 1.5 1993/01/30 12:55:49 glewis Exp $";
#include <stdio.h>
#include "t3dlib.h"
#ifdef __STDC__
#include <stdlib.h>
#include <strings.h>
#include "freeworld_protos.h"
#endif
#define myfree(x) {free((char *)x);x=NULL;}
/* free an OBJECT struct - recursive */
OBJECT *free_object(object)
OBJECT *object;
{
FGRP *fgrp;
register int i;
/* I follow the next chain, then the child chain. Glenn? */
if (object->next)
object->next = free_object(object->next);
if (object->child)
object->child = free_object(object->child);
/* free the easy parts */
if (object->extr)
myfree(object->extr);
if (object->user)
myfree(object->user);
/* free the DESC */
if (object->desc) {
if (object->desc->shap)
myfree(object->desc->shap);
if (object->desc->posi)
myfree(object->desc->posi);
if (object->desc->axis)
myfree(object->desc->axis);
if (object->desc->size)
myfree(object->desc->size);
if (object->desc->pnts)
myfree(object->desc->pnts);
if (object->desc->colr)
myfree(object->desc->colr);
if (object->desc->refl)
myfree(object->desc->refl);
if (object->desc->tran)
myfree(object->desc->tran);
if (object->desc->spc1)
myfree(object->desc->spc1);
if (object->desc->edge)
myfree(object->desc->edge);
if (object->desc->face)
myfree(object->desc->face);
if (object->desc->clst)
myfree(object->desc->clst);
if (object->desc->rlst)
myfree(object->desc->rlst);
if (object->desc->tlst)
myfree(object->desc->tlst);
if (object->desc->tpar)
myfree(object->desc->tpar);
if (object->desc->surf)
myfree(object->desc->surf);
if (object->desc->mttr)
myfree(object->desc->mttr);
if (object->desc->spec)
myfree(object->desc->spec);
if (object->desc->prp0)
myfree(object->desc->prp0);
if (object->desc->prp1)
myfree(object->desc->prp1);
if (object->desc->ints)
myfree(object->desc->ints);
if (object->desc->int1)
myfree(object->desc->int1);
if (object->desc->stry)
myfree(object->desc->stry);
if (object->desc->eflg) {
if (object->desc->eflg->eflg)
myfree(object->desc->eflg->eflg);
myfree(object->desc->eflg);
}
while (object->desc->fgrp) {
if (object->desc->fgrp->face)
myfree(object->desc->fgrp->face);
fgrp = object->desc->fgrp;
object->desc->fgrp = object->desc->fgrp->next;
myfree(fgrp);
}
for (i=0; i<4; i++) {
if (!object->desc->txt2[i]) continue;
myfree(object->desc->txt2[i]);
}
myfree(object->desc);
}
/* finally, free yourself */
free((char *)object);
return NULL;
}
/* free the WORLD - always returns NULL, for "World = free_World(World);" */
WORLD *free_World(World)
WORLD *World;
{
/* really have an object? */
if (!World)
return NULL;
/* free the substructures */
if (World->info) {
if (World->info->obsv)
myfree(World->info->obsv);
if (World->info->ostr)
myfree(World->info->ostr);
if (World->info->fade)
myfree(World->info->fade);
if (World->info->skyc)
myfree(World->info->skyc);
if (World->info->ambi)
myfree(World->info->ambi);
if (World->info->glb0)
myfree(World->info->glb0);
myfree(World->info);
}
if (World->object)
World->object = free_object(World->object);
if (World->user)
myfree(World->user);
/* I don't touch FILE *inp or OBJECT *curobj */
/* free the World */
free((char *)World);
return NULL;
}